// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.characters.CharacterTimedActions;

import se.krka.kahlua.vm.KahluaTable;
import zombie.Lua.LuaManager;
import zombie.characters.IsoGameCharacter;

public final class LuaTimedAction extends BaseAction {
    KahluaTable table;
    public static Object[] statObj = new Object[6];

    public LuaTimedAction(KahluaTable kahluaTable, IsoGameCharacter isoGameCharacter) {
        super(isoGameCharacter);
        this.table = kahluaTable;
        Object object0 = kahluaTable.rawget("maxTime");
        this.MaxTime = (Integer)LuaManager.converterManager.fromLuaToJava(object0, Integer.class);
        Object object1 = kahluaTable.rawget("stopOnWalk");
        Object object2 = kahluaTable.rawget("stopOnRun");
        Object object3 = kahluaTable.rawget("stopOnAim");
        Object object4 = kahluaTable.rawget("onUpdateFunc");
        if (object1 != null) {
            this.StopOnWalk = (Boolean)LuaManager.converterManager.fromLuaToJava(object1, Boolean.class);
        }

        if (object2 != null) {
            this.StopOnRun = (Boolean)LuaManager.converterManager.fromLuaToJava(object2, Boolean.class);
        }

        if (object3 != null) {
            this.StopOnAim = (Boolean)LuaManager.converterManager.fromLuaToJava(object3, Boolean.class);
        }
    }

    @Override
    public void update() {
        statObj[0] = this.table.rawget("character");
        statObj[1] = this.table.rawget("param1");
        statObj[2] = this.table.rawget("param2");
        statObj[3] = this.table.rawget("param3");
        statObj[4] = this.table.rawget("param4");
        statObj[5] = this.table.rawget("param5");
        LuaManager.caller.pcallvoid(LuaManager.thread, this.table.rawget("onUpdateFunc"), statObj);
        super.update();
    }

    @Override
    public boolean valid() {
        Object[] object = LuaManager.caller
            .pcall(
                LuaManager.thread,
                this.table.rawget("isValidFunc"),
                new Object[]{
                    this.table.rawget("character"),
                    this.table.rawget("param1"),
                    this.table.rawget("param2"),
                    this.table.rawget("param3"),
                    this.table.rawget("param4"),
                    this.table.rawget("param5")
                }
            );
        return object.length > 0 && (Boolean)object[0];
    }

    @Override
    public void start() {
        super.start();
        this.CurrentTime = 0.0F;
        LuaManager.caller
            .pcall(
                LuaManager.thread,
                this.table.rawget("startFunc"),
                new Object[]{
                    this.table.rawget("character"),
                    this.table.rawget("param1"),
                    this.table.rawget("param2"),
                    this.table.rawget("param3"),
                    this.table.rawget("param4"),
                    this.table.rawget("param5")
                }
            );
    }

    @Override
    public void stop() {
        super.stop();
        LuaManager.caller
            .pcall(
                LuaManager.thread,
                this.table.rawget("onStopFunc"),
                new Object[]{
                    this.table.rawget("character"),
                    this.table.rawget("param1"),
                    this.table.rawget("param2"),
                    this.table.rawget("param3"),
                    this.table.rawget("param4"),
                    this.table.rawget("param5")
                }
            );
    }

    @Override
    public void perform() {
        super.perform();
        LuaManager.caller
            .pcall(
                LuaManager.thread,
                this.table.rawget("performFunc"),
                new Object[]{
                    this.table.rawget("character"),
                    this.table.rawget("param1"),
                    this.table.rawget("param2"),
                    this.table.rawget("param3"),
                    this.table.rawget("param4"),
                    this.table.rawget("param5")
                }
            );
    }
}
